home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Fish Fillets / script / ending / code.lua next >
Text File  |  2005-07-16  |  10KB  |  282 lines

  1.  
  2. -- -----------------------------------------------------------------
  3. local function charAt(s, i)
  4.     return string.sub(s, i, i)
  5. end
  6. -- -----------------------------------------------------------------
  7. local function planHyb(unit, destX, destY)
  8.     local symbols
  9.     --NOTE: symbols order is as dir_up==1, ...
  10.     if unit == small then
  11.         symbols = "udlr"
  12.     else
  13.         symbols = "UDLR"
  14.     end
  15.     level_planShow(function(count)
  16.             local result = false
  17.             local dir = findDir(unit, destX, destY)
  18.             if dir == dir_no then
  19.                 room.natvrdo = 0
  20.                 result = true
  21.             else
  22.                 level_action_move(charAt(symbols, dir))
  23.             end
  24.             return result
  25.         end)
  26. end
  27.  
  28. -- -----------------------------------------------------------------
  29. -- Init
  30. -- -----------------------------------------------------------------
  31. local function prog_init()
  32.     initModels()
  33.     sound_playMusic("music/rybky04.ogg")
  34.     local pokus = getRestartCount()
  35.  
  36.  
  37.     -- -------------------------------------------------------------
  38.     local function prog_init_room()
  39.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  40.  
  41.         room.uvod = 0
  42.         room.hlaska = 0
  43.         zavermode = true
  44.  
  45.         return function()
  46.             if room.uvod == 0 then
  47.                 room.uvod = 1
  48.                 addv(20, "z-v-doma")
  49.                 addm(10, "z-m-pocit")
  50.                 planDialogSet(random(10) + 5, "bar-x-suckano", 202, pldik, "cinnost")
  51.                 addv(random(20) + 10, "z-v-sef")
  52.                 addm(5, "z-m-nemluv")
  53.                 addv(2, "z-v-slyset")
  54.                 addm(6, "z-m-netusi")
  55.                 room:planDialog(5, "z-c-konkretne")
  56.                 adddel(3)
  57.                 planSet(room, "hlaska", 1)
  58.             elseif room.uvod == 2 then
  59.                 room.uvod = 3
  60.                 adddel(5)
  61.                 planTimeAction(0, function() planHyb(small, 14, 16) end)
  62.                 addm(5, "z-m-dlouho")
  63.                 planBusy(big, true)
  64.                 addv(10, "z-v-pozdrav")
  65.                 planBusy(small, true)
  66.                 planBusy(big, false)
  67.                 addm(5, "z-m-oblicej")
  68.                 planTimeAction(0, function() planHyb(big, 15, 15) end)
  69.                 addv(0, "z-v-forky")
  70.                 adddel(2)
  71.                 planBusy(big, true)
  72.                 planBusy(small, true)
  73.                 planDialog(TALK_INDEX_BOTH, 2, "z-o-blahoprejeme")
  74.                 adddel(20)
  75.                 planBusy(big, false)
  76.                 planBusy(small, false)
  77.             end
  78.             if room.hlaska == 1 then
  79.                 room.cas = math.floor(0.5 +
  80.                         optionsGetAsInt("playtime") / 3600)
  81.             end
  82.             if room.hlaska >= 1 and not room:isTalking() then
  83.                 pom1 = room.hlaska
  84.                 room.hlaska = room.hlaska + 1
  85.                 if room.cas >= 1000 then
  86.                     if room.cas >= 2000 then
  87.                         pom1 = pom1 - 1
  88.                         if pom1 == 0 then
  89.                             room:talk("z-c-"..(math.floor(room.cas / 1000)))
  90.                         end
  91.                     end
  92.                     if isIn(math.floor(room.cas / 1000), {2, 3, 4}) then
  93.                         pom1 = pom1 - 1
  94.                         if pom1 == 0 then
  95.                             room:talk("z-c-tisice")
  96.                         end
  97.                     else
  98.                         pom1 = pom1 - 1
  99.                         if pom1 == 0 then
  100.                             room:talk("z-c-tisic")
  101.                         end
  102.                     end
  103.                 end
  104.                 switch(math.floor(math.mod(room.cas, 1000) / 100)){
  105.                     [0] = function()
  106.                     end,
  107.                     [1] = function()
  108.                         pom1 = pom1 - 1
  109.                         if pom1 == 0 then
  110.                             room:talk("z-c-100")
  111.                         end
  112.                     end,
  113.                     [2] = function()
  114.                         pom1 = pom1 - 1
  115.                         if pom1 == 0 then
  116.                             room:talk("z-c-200")
  117.                         end
  118.                     end,
  119.                     [3] = function()
  120.                         pom1 = pom1 - 1
  121.                         if pom1 == 0 then
  122.                             room:talk("z-c-"..(math.floor(math.mod(room.cas, 1000) / 100)))
  123.                         end
  124.                         pom1 = pom1 - 1
  125.                         if pom1 == 0 then
  126.                             room:talk("z-c-sta")
  127.                         end
  128.                     end,
  129.                     [4] = function()
  130.                         pom1 = pom1 - 1
  131.                         if pom1 == 0 then
  132.                             room:talk("z-c-"..(math.floor(math.mod(room.cas, 1000) / 100)))
  133.                         end
  134.                         pom1 = pom1 - 1
  135.                         if pom1 == 0 then
  136.                             room:talk("z-c-sta")
  137.                         end
  138.                     end,
  139.                     default = function()
  140.                         pom1 = pom1 - 1
  141.                         if pom1 == 0 then
  142.                             room:talk("z-c-"..(math.floor(math.mod(room.cas, 1000) / 100)))
  143.                         end
  144.                         pom1 = pom1 - 1
  145.                         if pom1 == 0 then
  146.                             room:talk("z-c-set")
  147.                         end
  148.                     end,
  149.                 }
  150.                 if math.mod(room.cas, 100) < 20 and math.mod(room.cas, 100) > 0 then
  151.                     pom1 = pom1 - 1
  152.                     if pom1 == 0 then
  153.                         room:talk("z-c-"..(math.mod(room.cas, 100)))
  154.                     end
  155.                 elseif math.mod(room.cas, 100) >= 20 then
  156.                     pom1 = pom1 - 1
  157.                     if pom1 == 0 then
  158.                         room:talk("z-c-"..(math.floor(math.mod(room.cas, 100) / 10) * 10))
  159.                     end
  160.                     if math.mod(room.cas, 10) > 0 then
  161.                         pom1 = pom1 - 1
  162.                         if pom1 == 0 then
  163.                             room:talk("z-c-"..(math.mod(room.cas, 10)))
  164.                         end
  165.                     end
  166.                 end
  167.                 pom1 = pom1 - 1
  168.                 if pom1 == 0 then
  169.                     room.hlaska = 0
  170.                     room:talk("z-c-hodin@"..room.cas)
  171.                     room.uvod = 2
  172.                 end
  173.             end
  174.         end
  175.     end
  176.  
  177.     -- -------------------------------------------------------------
  178.     local function prog_init_pldik()
  179.         local pom1, pom2, pomb1, pomb2 = 0, 0, false, false
  180.  
  181.         pldik.cinnost = 0
  182.         pldik.oci = 0
  183.         pldik.suckani = 0
  184.         local ACTOR_SUCK = 251
  185.  
  186.         return function()
  187.             switch(pldik.cinnost){
  188.                 [0] = function()
  189.                     if random(1000) < 5 then
  190.                         pldik.cinnost = 1
  191.                     end
  192.                     if random(100) < 5 then
  193.                         pldik.oci = random(5)
  194.                         if pldik.oci > 0 then
  195.                             pldik.oci = pldik.oci + 1
  196.                         end
  197.                     end
  198.                     if pldik.suckani == 0 and random(100) < 2 then
  199.                         pldik.suckani = random(5) + 1
  200.                         pldik.suckfaze = 0
  201.                     end
  202.                 end,
  203.                 [1] = function()
  204.                     if random(1000) < 10 then
  205.                         pldik.cinnost = 0
  206.                     end
  207.                     pldik.oci = 6
  208.                     if pldik.suckani == 0 and random(100) < 2 then
  209.                         pldik.suckani = random(4) + 1
  210.                         pldik.suckfaze = 0
  211.                     end
  212.                 end,
  213.                 [202] = function()
  214.                     model_killSound(ACTOR_SUCK)
  215.                     if not pldik:isTalking() then
  216.                         pldik.cinnost = 0
  217.                     end
  218.                     pldik.oci = 0
  219.                     if pldik.suckani == 0 then
  220.                         pldik.suckani = 1000
  221.                         pldik.suckfaze = 0
  222.                     end
  223.                 end,
  224.             }
  225.             pldik.afaze = pldik.oci * 2
  226.             if random(100) < 5 then
  227.                 pldik.afaze = 12
  228.             end
  229.             if pldik.suckani > 0 then
  230.                 switch(pldik.suckfaze){
  231.                     [0] = function()
  232.                         if pldik.cinnost < 200 then
  233.                             model_talk(ACTOR_SUCK, "bar-x-suck"..random(4), VOLUME_FULL)
  234.                         end
  235.                     end,
  236.                     [1] = function()
  237.                         pldik.afaze = pldik.afaze + 1
  238.                     end,
  239.                     [2] = function()
  240.                         pldik.afaze = pldik.afaze + 1
  241.                     end,
  242.                     [3] = function()
  243.                         pldik.afaze = pldik.afaze + 1
  244.                     end,
  245.                     [5] = function()
  246.                         pldik.suckani = pldik.suckani - 1
  247.                     end,
  248.                 }
  249.                 pldik.suckfaze = math.mod(pldik.suckfaze + 1, 6)
  250.             else
  251.                 model_killSound(ACTOR_SUCK)
  252.             end
  253.             pldik:updateAnim()
  254.         end
  255.     end
  256.  
  257.     -- --------------------
  258.     local update_table = {}
  259.     local subinit
  260.     subinit = prog_init_room()
  261.     if subinit then
  262.         table.insert(update_table, subinit)
  263.     end
  264.     subinit = prog_init_pldik()
  265.     if subinit then
  266.         table.insert(update_table, subinit)
  267.     end
  268.     return update_table
  269. end
  270. local update_table = prog_init()
  271.  
  272.  
  273. -- -----------------------------------------------------------------
  274. -- Update
  275. -- -----------------------------------------------------------------
  276. function prog_update()
  277.     for key, subupdate in pairs(update_table) do
  278.         subupdate()
  279.     end
  280. end
  281.  
  282.